package com.wanmait.schedule.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.wanmait.schedule.entity.Classes;
import com.wanmait.schedule.mapper.ClassesMapper;
import com.wanmait.schedule.service.ClassesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import java.util.List;

/**
 * <p>
 * 班级表 服务实现类
 * </p>
 *
 * @author wanmait
 * @since 2022-12-05
 */
@Service
public class ClassesServiceImpl extends ServiceImpl<ClassesMapper, Classes> implements ClassesService {
    @Resource
    private ClassesMapper classesMapper;

    @Override
    public List<Classes> findNotGraduation(Integer id) {
        LambdaQueryChainWrapper<Classes> chainWrapper = new LambdaQueryChainWrapper(classesMapper);
        List<Classes> classesList = chainWrapper
                .eq(Classes::getMerge, 0)
                .eq(Classes::getGraduation, 0)
                .eq(Classes::getClassesTypeId,id)
                .gt(Classes::getStudentCount,0)
                .list();
        return classesList;
    }

    @Override
    public List<Classes> listClasses() {
        //return classesMapper.list(null);
        LambdaQueryChainWrapper<Classes> wrapper = new LambdaQueryChainWrapper(classesMapper);
        List<Classes> classesList = wrapper
                .in(Classes::getMerge, 0,1)
                .eq(Classes::getGraduation, 0)
                .list();
        return classesList;
    }

    @Override
    public PageInfo<Classes> list(Classes classes, Integer pageNum) {
        if(pageNum==null){
            pageNum=1;
        }
        PageHelper.startPage(pageNum,5);
        List<Classes> classesList = classesMapper.list(classes);
        PageInfo<Classes> pageInfo = new PageInfo<>(classesList,7);
        return pageInfo;
    }

    @Override
    public Classes findById(Integer id) {
        return classesMapper.findById(id);
    }
}
